<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="font/iconfont.css">
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        #box {
            width: 250px;
            height: 310px;
            border: 1px solid;
            padding: 5px 10px;
            margin: 50px auto;
        }

        .heng {
            display: flex;
            justify-content: space-between;
            height: 40px;
            line-height: 40px;
            
        }
        .hang{
            height: 60px;
            margin-top: 20px;
        }
        .left{
            font-weight: bold;
        }
        .tu{
            float: left;
        }
        .zi{
            float: left;
            margin-left: 5px;
        }
        .shu{
            float: right;
        }
        .shang{
            font-weight: bold;
            font-size: 14px;
        }
        .xia{
            margin-top: 15px;
        }
        .xia span{
            font-size: 18px;
            color: red;
        }
        .xia del{
            font-size: 14px;
         color: #eee;
        }
        .jian{
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 2px solid #00a6ff;
            border-radius: 50%;
            text-align: center;
            line-height: 12px;
            color: #00a6ff;
            font-size: 22px;
        }
        .jia{
            display: inline-block;
            width: 20px;
            height: 20px;
            background-color: #00a6ff;
            border-radius: 50%;
            text-align: center;
            line-height: 16px;
            color: white;
            font-size: 22px;
        }
        .shu{
            margin-top: 36px;
        }
        .suan{
            display: flex;
            justify-content: space-around;
        }
    </style>
</head>

<body>
    <div id="box">
        <div class="heng">
            <div class="left">已选商品</div>
            <div class="right" @click="delet">
                <span class="iconfont icon-shanchu-01"></span>
                <span>清空</span>
            </div>
        </div>
        <div class="hang" v-for="(item,index) in list" v-bind:key="index">
            <div class="tu">
                <img v-bind:src="item.pic" alt="">
            </div>
            <div class="zi">
                <div class="shang">{{item.name}}</div>
                <div class="xia"><span>{{item.jia}}</span> <del>{{item.shan}}</del></div>
            </div>
            <div class="shu">
                <span class="jian" @click="jian(item)">-</span>
                <span class="shuzi">{{item.shu}}</span>
                <span class="jia" @click="jia(item)">+</span>
            </div>
        </div>
        <div class="suan">
            <div class="he">总数:{{zongshu}}</div>
            <div class="zong">总价:{{zongjia}}</div>
        </div>

    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v=new Vue({
        el:'#box',
        data:{
            list:[
                {id:1,pic:'images/03.gif',name:'秋刀鱼/斤',jia:'35.00 ',shan:'￥35',shu:1},
                {id:1,pic:'images/06.gif',name:'鲜大带鱼/条',jia:'45.00 ',shan:'￥45',shu:1},
                {id:1,pic:'images/08.gif',name:'鲜活全母皮皮虾/斤',jia:'85.00 ',shan:'￥85',shu:1},
            ]
        },
        methods:{
            jia(item){
                if(item.shu<5){
                    item.shu++
                }
            },
            jian(item){
                if(item.shu>1){
                    item.shu--
                }
            },
            delet(){
               this.list.splice(0,this.list.length)
            }
        },
        computed:{
            zongshu(){
                var shu=0
                this.list.forEach((item) => {
                    shu+=item.shu
                });
                return shu
            },
            zongjia(){
                var price = this.list.reduce((t, item) => {
                return t + item.jia * item.shu;
            }, 0)
            return price
            }
        }

    })
</script>